<?php
namespace Admin\Controller;
use Think\Controller;
class TypeController extends BaseController {
    public function showlist(){
		$type = D('type');
		$count = $type->count();
		$Page = new \Think\Page($count,3);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$Page->setConfig('prev','上一页');
		$Page->setConfig('next','下一页');
		$show = $Page->show();// 分页显示输出
		$typeRes = $type->limit($Page->firstRow.','.$Page->listRows)->select();//数据
		$this->page = $show;
		$this->typeRes = $typeRes;
		$this->num = 1; //用于标记栏目数
        $this->display();
    }
	
	public function addCol(){
	
		if (IS_POST){
			$type = D('type');
			if( $type->create() ){
				$type->add();
				$this->success('添加栏目完成',U('showlist') );
			}else{
				$this->error( $type->getError(),U('addCol') );
			}
			return;
		}
        $this->display();
    }
	
	public function updateCol(){
		
		$typename = I('typename'); 
		$tid = I('tid');
		
		//updateCol定向到自己
		if (IS_POST){
			$type = D('type');
			if( $temp = $type->create() ){
				$where['tid']=':tid';
				$bind[':tid'] = $tid;
				$type->where($where)->bind($bind)->save();
				$this->success('修改栏目名称成功',U('showlist') );
			}else{
				$this->error( $type->getError(),U('Admin/Type/updateCol/typename/'.$typename) );
			}
			return;
		}
		
		//showlist定向到updateCol
		if(IS_GET){
			$this->typename = $typename;
			$this->tid = $tid;
		}
		$this->display();
	}
	
	public function deleteCol(){
		if( $tid = I('tid') ){
			$type = M('type');
			$type->delete($tid);
			$this->success('修改栏目名称成功',U('showlist') );
		}else{
			$this->error('删除栏目失败',U('showlist') );
		}
	}
	
	
	
	
	
	
	
	
	
}